home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / What's New / Development Kits / Mac_OS_USB_DDK_v1.2 / USB.h < prev   
Encoding:
C/C++ Source or Header  |  1999-04-15  |  34.3 KB  |  1,241 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    
  7.  
  8. */
  9. #ifndef __USB__
  10. #define __USB__
  11.  
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __NAMEREGISTRY__
  16. #include <NameRegistry.h>
  17. #endif
  18. #ifndef __CODEFRAGMENTS__
  19. #include <CodeFragments.h>
  20. #endif
  21. #ifndef __DEVICES__
  22. #include <Devices.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /* ************* Constants ************* */
  48. enum {
  49.     kUSBNoErr                    = 0,
  50.     kUSBNoTran                    = 0,
  51.     kUSBNoDelay                    = 0,
  52.     kUSBPending                    = 1,                            /* */
  53.                                                                 /* USB assigned error numbers in range -6900 .. -6999 */
  54.     kUSBBaseError                = -7000,                        /* */
  55.                                                                 /* USB Services Errors */
  56.     kUSBInternalErr                = -6999,                        /* Internal error */
  57.     kUSBUnknownDeviceErr        = -6998,                        /*  device ref not recognised */
  58.     kUSBUnknownPipeErr            = -6997,                        /*  Pipe ref not recognised */
  59.     kUSBTooManyPipesErr            = -6996,                        /*  Too many pipes */
  60.     kUSBIncorrectTypeErr        = -6995,                        /*  Incorrect type */
  61.     kUSBRqErr                    = -6994,                        /*  Request error */
  62.     kUSBUnknownRequestErr        = -6993,                        /*  Unknown request */
  63.     kUSBTooManyTransactionsErr    = -6992,                        /*  Too many transactions */
  64.     kUSBAlreadyOpenErr            = -6991,                        /*  Already open */
  65.     kUSBNoDeviceErr                = -6990,                        /*  No device */
  66.     kUSBDeviceErr                = -6989,                        /*  Device error */
  67.     kUSBOutOfMemoryErr            = -6988,                        /*  Out of memory */
  68.     kUSBNotFound                = -6987,                        /*  Not found */
  69.     kUSBPBVersionError            = -6986,                        /*  Wrong pbVersion */
  70.     kUSBPBLengthError            = -6985,                        /*  pbLength too small */
  71.     kUSBCompletionError            = -6984,                        /*  no completion routine specified */
  72.     kUSBFlagsError                = -6983,                        /*  Unused flags not zeroed */
  73.     kUSBAbortedError            = -6982,                        /*  Pipe aborted */
  74.     kUSBNoBandwidthError        = -6981,                        /*  Not enough bandwidth available */
  75.     kUSBPipeIdleError            = -6980,                        /*  Pipe is Idle, it will not accept transactions */
  76.     kUSBPipeStalledError        = -6979,                        /*  Pipe has stalled, error needs to be cleared */
  77.     kUSBUnknownInterfaceErr        = -6978,                        /*  Interface ref not recognised */
  78.     kUSBDeviceBusy                = -6977,                        /*  Device is already being configured */
  79.     kUSBDevicePowerProblem        = -6976,                        /*  Device has a power problem */
  80.     kUSBInvalidBuffer            = -6975,                        /* bad buffer, usually nil */
  81.                                                                 /* */
  82.                                                                 /* USB Manager Errors */
  83.     kUSBBadDispatchTable        = -6950,                        /* Improper driver dispatch table */
  84.     kUSBUnknownNotification        = -6949,                        /* Notification type not defined */
  85.     kUSBQueueFull                = -6948,                        /* Internal queue maxxed */
  86.                                                                 /* */
  87.                                                                 /* Hardware Errors */
  88.                                                                 /* Note pipe stalls are communication */
  89.                                                                 /* errors. The affected pipe can not */
  90.                                                                 /* be used until USBClearPipeStallByReference  */
  91.                                                                 /* is used */
  92.                                                                 /* kUSBEndpointStallErr is returned in */
  93.                                                                 /* response to a stall handshake */
  94.                                                                 /* from a device. The device has to be */
  95.                                                                 /* cleared before a USBClearPipeStallByReference */
  96.                                                                 /* can be used */
  97.     kUSBLinkErr                    = -6916,
  98.     kUSBCRCErr                    = -6915,                        /*  Pipe stall, bad CRC */
  99.     kUSBBitstufErr                = -6914,                        /*  Pipe stall, bitstuffing */
  100.     kUSBDataToggleErr            = -6913,                        /*  Pipe stall, Bad data toggle */
  101.     kUSBEndpointStallErr        = -6912,                        /*  Device didn't understand */
  102.     kUSBNotRespondingErr        = -6911,                        /*  Pipe stall, No device, device hung */
  103.     kUSBPIDCheckErr                = -6910,                        /*  Pipe stall, PID CRC error */
  104.     kUSBWrongPIDErr                = -6909,                        /*  Pipe stall, Bad or wrong PID */
  105.     kUSBOverRunErr                = -6908,                        /*  Packet too large or more data than buffer */
  106.     kUSBUnderRunErr                = -6907,                        /*  Less data than buffer */
  107.     kUSBRes1Err                    = -6906,
  108.     kUSBRes2Err                    = -6905,
  109.     kUSBBufOvrRunErr            = -6904,                        /*  Host hardware failure on data in, PCI busy? */
  110.     kUSBBufUnderRunErr            = -6903,                        /*  Host hardware failure on data out, PCI busy? */
  111.     kUSBNotSent1Err                = -6902,                        /*  Transaction not sent */
  112.     kUSBNotSent2Err                = -6901                            /*  Transaction not sent */
  113. };
  114.  
  115. enum {
  116.                                                                 /* Flags */
  117.     kUSBTaskTimeFlag            = 1,
  118.     kUSBHubPower                = 2,
  119.     kUSBPowerReset                = 4,
  120.     kUSBHubReaddress            = 8,
  121.     kUSBAddressRequest            = 16
  122. };
  123.  
  124. enum {
  125.                                                                 /* Hub messages */
  126.     kUSBHubPortResetRequest        = 1
  127. };
  128.  
  129. enum {
  130.     kVendorID_AppleComputer        = 0x05AC
  131. };
  132.  
  133. /* ************* types ************* */
  134.  
  135. typedef SInt32                             USBReference;
  136. typedef USBReference                     USBDeviceRef;
  137. typedef USBReference                     USBInterfaceRef;
  138. typedef USBReference                     USBPipeRef;
  139. typedef USBReference                     USBBusRef;
  140. typedef UInt32                             USBPipeState;
  141. typedef UInt32                             USBCount;
  142. typedef UInt32                             USBFlags;
  143. typedef UInt8                             USBRequest;
  144. typedef UInt8                             USBDirection;
  145. typedef UInt8                             USBRqRecipient;
  146. typedef UInt8                             USBRqType;
  147. typedef UInt16                             USBRqIndex;
  148. typedef UInt16                             USBRqValue;
  149.  
  150.  
  151.  
  152. struct usbControlBits {
  153.     UInt8                             BMRequestType;
  154.     UInt8                             BRequest;
  155.     USBRqValue                         WValue;
  156.     USBRqIndex                         WIndex;
  157.     UInt16                             reserved4;
  158. };
  159. typedef struct usbControlBits            usbControlBits;
  160.  
  161. struct USBIsocFrame {
  162.     OSStatus                         frStatus;
  163.     UInt16                             frReqCount;
  164.     UInt16                             frActCount;
  165. };
  166. typedef struct USBIsocFrame                USBIsocFrame;
  167.  
  168. struct usbIsocBits {
  169.     USBIsocFrame *                    FrameList;
  170.     UInt32                             NumFrames;
  171. };
  172. typedef struct usbIsocBits                usbIsocBits;
  173.  
  174. struct usbHubBits {
  175.     UInt32                             Request;
  176.     UInt32                             Spare;
  177. };
  178. typedef struct usbHubBits                usbHubBits;
  179. typedef struct USBPB                     USBPB;
  180. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  181.  
  182. union USBVariantBits {
  183.     usbControlBits                     cntl;
  184.     usbIsocBits                     isoc;
  185.     usbHubBits                         hub;
  186. };
  187. typedef union USBVariantBits            USBVariantBits;
  188.  
  189. struct USBPB {
  190.  
  191.     void *                            qlink;
  192.     UInt16                             qType;
  193.     UInt16                             pbLength;
  194.     UInt16                             pbVersion;
  195.     UInt16                             reserved1;
  196.     UInt32                             reserved2;
  197.  
  198.     OSStatus                         usbStatus;
  199.     USBCompletion                     usbCompletion;
  200.     UInt32                             usbRefcon;
  201.  
  202.     USBReference                     usbReference;
  203.  
  204.     void *                            usbBuffer;
  205.     USBCount                         usbReqCount;
  206.     USBCount                         usbActCount;
  207.  
  208.     USBFlags                         usbFlags;
  209.  
  210.     USBVariantBits                     usb;
  211.  
  212.     UInt32                             usbFrame;
  213.  
  214.     UInt8                             usbClassType;
  215.     UInt8                             usbSubclass;
  216.     UInt8                             usbProtocol;
  217.     UInt8                             usbOther;
  218.  
  219.     UInt32                             reserved6;
  220.     UInt16                             reserved7;
  221.     UInt16                             reserved8;
  222.  
  223. };
  224.  
  225.  
  226. typedef USBPB *                            USBPBPtr;
  227. #if !defined(OLDUSBNAMES)
  228. #define OLDUSBNAMES 0
  229. #endif
  230.  
  231. #if OLDUSBNAMES
  232. #define usbBMRequestType  usb.cntl.BMRequestType
  233. #define usbBRequest       usb.cntl.BRequest
  234. #define usbWValue         usb.cntl.WValue
  235. #define usbWIndex         usb.cntl.WIndex
  236. #endif
  237.  
  238. struct uslReq {
  239.     USBDirection                     usbDirection;
  240.     USBRqType                         usbType;
  241.     USBRqRecipient                     usbRecipient;
  242.     USBRequest                         usbRequest;
  243. };
  244. typedef struct uslReq                    uslReq;
  245.  
  246. enum {
  247.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  248.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  249.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  250.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  251. };
  252.  
  253.  
  254.  
  255.  
  256. #define kUSBNoCallBack ((USBCompletion)-1L)
  257.  
  258.  
  259. typedef UInt8                             bcdUSB;
  260. enum {
  261.     kUSBControl                    = 0,
  262.     kUSBIsoc                    = 1,
  263.     kUSBBulk                    = 2,
  264.     kUSBInterrupt                = 3,
  265.     kUSBAnyType                    = 0xFF
  266. };
  267.  
  268. /* endpoint type */
  269. enum {
  270.     kUSBOut                        = 0,
  271.     kUSBIn                        = 1,
  272.     kUSBNone                    = 2,
  273.     kUSBAnyDirn                    = 3
  274. };
  275.  
  276. /*USBDirection*/
  277. enum {
  278.     kUSBStandard                = 0,
  279.     kUSBClass                    = 1,
  280.     kUSBVendor                    = 2
  281. };
  282.  
  283. /*USBRqType*/
  284. enum {
  285.     kUSBDevice                    = 0,
  286.     kUSBInterface                = 1,
  287.     kUSBEndpoint                = 2,
  288.     kUSBOther                    = 3
  289. };
  290.  
  291. /*USBRqRecipient*/
  292. enum {
  293.     kUSBRqGetStatus                = 0,
  294.     kUSBRqClearFeature            = 1,
  295.     kUSBRqReserved1                = 2,
  296.     kUSBRqSetFeature            = 3,
  297.     kUSBRqReserved2                = 4,
  298.     kUSBRqSetAddress            = 5,
  299.     kUSBRqGetDescriptor            = 6,
  300.     kUSBRqSetDescriptor            = 7,
  301.     kUSBRqGetConfig                = 8,
  302.     kUSBRqSetConfig                = 9,
  303.     kUSBRqGetInterface            = 10,
  304.     kUSBRqSetInterface            = 11,
  305.     kUSBRqSyncFrame                = 12
  306. };
  307.  
  308. /*USBRequest*/
  309.  
  310. enum {
  311.     kUSBDeviceDesc                = 1,
  312.     kUSBConfDesc                = 2,
  313.     kUSBStringDesc                = 3,
  314.     kUSBInterfaceDesc            = 4,
  315.     kUSBEndpointDesc            = 5,
  316.     kUSBHIDDesc                    = 0x21,
  317.     kUSBReportDesc                = 0x22,
  318.     kUSBPhysicalDesc            = 0x23,
  319.     kUSBHUBDesc                    = 0x29
  320. };
  321.  
  322. /* descriptorType */
  323.  
  324. enum {
  325.     kUSBFeatureDeviceRemoteWakeup = 1,
  326.     kUSBFeatureEndpointStall    = 0
  327. };
  328.  
  329. /* Feature selectors */
  330. enum {
  331.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  332.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  333.     kUSBStalled                    = 2                                /* An error occured on the pipe*/
  334. };
  335.  
  336. enum {
  337.     kUSB100mAAvailable            = 50,
  338.     kUSB500mAAvailable            = 250,
  339.     kUSB100mA                    = 50,
  340.     kUSBAtrBusPowered            = 0x80,
  341.     kUSBAtrSelfPowered            = 0x40,
  342.     kUSBAtrRemoteWakeup            = 0x20
  343. };
  344.  
  345. enum {
  346.     kUSBRel10                    = 0x0100
  347. };
  348.  
  349. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  350. enum {
  351.     kUSBDeviceDescriptorLength    = 0x12,
  352.     kUSBInterfaceDescriptorLength = 0x09
  353. };
  354.  
  355.  
  356. struct USBDeviceDescriptor {
  357.     UInt8                             length;
  358.     UInt8                             descType;
  359.     UInt16                             usbRel;
  360.     UInt8                             deviceClass;
  361.     UInt8                             deviceSubClass;
  362.     UInt8                             protocol;
  363.     UInt8                             maxPacketSize;
  364.     UInt16                             vendor;
  365.     UInt16                             product;
  366.     UInt16                             devRel;
  367.     UInt8                             manuIdx;
  368.     UInt8                             prodIdx;
  369.     UInt8                             serialIdx;
  370.     UInt8                             numConf;
  371.     UInt16                             descEnd;                    /* was "end", but this is reserved in some languages*/
  372. };
  373. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  374. #ifndef OLDCLASSNAMES
  375. #ifndef __cplusplus
  376. #define class deviceClass
  377. #define subClass deviceSubClass
  378. #endif
  379. #endif
  380. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  381.  
  382. struct USBDescriptorHeader {
  383.     UInt8                             length;
  384.     UInt8                             descriptorType;
  385. };
  386. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  387. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  388.  
  389. struct USBConfigurationDescriptor {
  390.     UInt8                             length;
  391.     UInt8                             descriptorType;
  392.     UInt16                             totalLength;
  393.     UInt8                             numInterfaces;
  394.     UInt8                             configValue;
  395.     UInt8                             configStrIndex;
  396.     UInt8                             attributes;
  397.     UInt8                             maxPower;
  398. };
  399. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  400. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  401.  
  402. struct USBInterfaceDescriptor {
  403.     UInt8                             length;
  404.     UInt8                             descriptorType;
  405.     UInt8                             interfaceNumber;
  406.     UInt8                             alternateSetting;
  407.     UInt8                             numEndpoints;
  408.     UInt8                             interfaceClass;
  409.     UInt8                             interfaceSubClass;
  410.     UInt8                             interfaceProtocol;
  411.     UInt8                             interfaceStrIndex;
  412. };
  413. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  414. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  415.  
  416. struct USBEndPointDescriptor {
  417.     UInt8                             length;
  418.     UInt8                             descriptorType;
  419.     UInt8                             endpointAddress;
  420.     UInt8                             attributes;
  421.     UInt16                             maxPacketSize;
  422.     UInt8                             interval;
  423. };
  424. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  425. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  426.  
  427. struct USBHIDDescriptor {
  428.     UInt8                             descLen;
  429.     UInt8                             descType;
  430.     UInt16                             descVersNum;
  431.     UInt8                             hidCountryCode;
  432.     UInt8                             hidNumDescriptors;
  433.     UInt8                             hidDescriptorType;
  434.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  435.     UInt8                             hidDescriptorLengthHi;
  436. };
  437. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  438. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  439.  
  440. struct USBHIDReportDesc {
  441.     UInt8                             hidDescriptorType;
  442.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  443.     UInt8                             hidDescriptorLengthHi;
  444. };
  445. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  446. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  447.  
  448. struct USBHubPortStatus {
  449.     UInt16                             portFlags;                    /* Port status flags */
  450.     UInt16                             portChangeFlags;            /* Port changed flags */
  451. };
  452. typedef struct USBHubPortStatus            USBHubPortStatus;
  453. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  454. /* ********* ProtoTypes *************** */
  455. /* For dealing with endianisms */
  456. EXTERN_API_C( UInt16 )
  457. HostToUSBWord                    (UInt16                 value);
  458.  
  459. EXTERN_API_C( UInt16 )
  460. USBToHostWord                    (UInt16                 value);
  461.  
  462. EXTERN_API_C( UInt32 )
  463. HostToUSBLong                    (UInt32                 value);
  464.  
  465. EXTERN_API_C( UInt32 )
  466. USBToHostLong                    (UInt32                 value);
  467.  
  468. /* Main prototypes */
  469. /* Transfer commands */
  470. EXTERN_API_C( OSStatus )
  471. USBDeviceRequest                (USBPB *                pb);
  472.  
  473. EXTERN_API_C( OSStatus )
  474. USBOpenPipe                        (USBPB *                pb);
  475.  
  476. EXTERN_API_C( OSStatus )
  477. USBBulkWrite                    (USBPB *                pb);
  478.  
  479. EXTERN_API_C( OSStatus )
  480. USBBulkRead                        (USBPB *                pb);
  481.  
  482. EXTERN_API_C( OSStatus )
  483. USBIntRead                        (USBPB *                pb);
  484.  
  485. EXTERN_API_C( OSStatus )
  486. USBIntWrite                        (USBPB *                pb);
  487.  
  488. EXTERN_API_C( OSStatus )
  489. USBIsocRead                        (USBPB *                pb);
  490.  
  491. EXTERN_API_C( OSStatus )
  492. USBIsocWrite                    (USBPB *                pb);
  493.  
  494. /* Pipe state control */
  495. EXTERN_API_C( OSStatus )
  496. USBClearPipeStallByReference    (USBPipeRef             ref);
  497.  
  498. EXTERN_API_C( OSStatus )
  499. USBAbortPipeByReference            (USBReference             ref);
  500.  
  501. EXTERN_API_C( OSStatus )
  502. USBResetPipeByReference            (USBReference             ref);
  503.  
  504. EXTERN_API_C( OSStatus )
  505. USBSetPipeIdleByReference        (USBPipeRef             ref);
  506.  
  507. EXTERN_API_C( OSStatus )
  508. USBSetPipeActiveByReference        (USBPipeRef             ref);
  509.  
  510. EXTERN_API_C( OSStatus )
  511. USBClosePipeByReference            (USBPipeRef             ref);
  512.  
  513. EXTERN_API_C( OSStatus )
  514. USBGetPipeStatusByReference        (USBReference             ref,
  515.                                  USBPipeState *            state);
  516.  
  517.  
  518. /* Configuration services */
  519. EXTERN_API_C( OSStatus )
  520. USBFindNextInterface            (USBPB *                pb);
  521.  
  522. EXTERN_API_C( OSStatus )
  523. USBOpenDevice                    (USBPB *                pb);
  524.  
  525. EXTERN_API_C( OSStatus )
  526. USBSetConfiguration                (USBPB *                pb);
  527.  
  528. EXTERN_API_C( OSStatus )
  529. USBNewInterfaceRef                (USBPB *                pb);
  530.  
  531. EXTERN_API_C( OSStatus )
  532. USBDisposeInterfaceRef            (USBPB *                pb);
  533.  
  534. EXTERN_API_C( OSStatus )
  535. USBConfigureInterface            (USBPB *                pb);
  536.  
  537. EXTERN_API_C( OSStatus )
  538. USBFindNextPipe                    (USBPB *                pb);
  539.  
  540.  
  541. /* Dealing with descriptors. */
  542. /* Note most of this is temprorary */
  543. EXTERN_API_C( OSStatus )
  544. USBGetConfigurationDescriptor    (USBPB *                pb);
  545.  
  546. EXTERN_API_C( OSStatus )
  547. USBGetFullConfigurationDescriptor (USBPB *                pb);
  548.  
  549. EXTERN_API_C( OSStatus )
  550. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  551.  
  552. EXTERN_API_C( OSStatus )
  553. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  554.  
  555. EXTERN_API_C( OSStatus )
  556. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  557.  
  558.  
  559.  
  560. /* Utility functions */
  561. EXTERN_API_C( OSStatus )
  562. USBResetDevice                    (USBPB *                pb);
  563.  
  564. EXTERN_API_C( OSStatus )
  565. USBGetFrameNumberImmediate        (USBPB *                pb);
  566.  
  567. EXTERN_API_C( OSStatus )
  568. USBDelay                        (USBPB *                pb);
  569.  
  570. EXTERN_API_C( OSStatus )
  571. USBAllocMem                        (USBPB *                pb);
  572.  
  573. EXTERN_API_C( OSStatus )
  574. USBDeallocMem                    (USBPB *                pb);
  575.  
  576. /* Expert interface functions */
  577. EXTERN_API_C( OSStatus )
  578. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  579.                                  USBDeviceDescriptorPtr  desc,
  580.                                  USBInterfaceDescriptorPtr  interfacePtr,
  581.                                  USBReference             hubRef,
  582.                                  UInt32                 busPowerAvailable);
  583.  
  584. EXTERN_API_C( OSStatus )
  585. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  586.  
  587. EXTERN_API_C( OSStatus )
  588. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  589.                                  USBDeviceDescriptorPtr  desc,
  590.                                  USBReference             hubRef,
  591.                                  UInt32                 port,
  592.                                  UInt32                 busPowerAvailable);
  593.  
  594. EXTERN_API_C( OSStatus )
  595. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  596.  
  597. EXTERN_API_C( OSStatus )
  598. USBExpertStatus                    (USBDeviceRef             ref,
  599.                                  void *                    pointer,
  600.                                  UInt32                 value);
  601.  
  602. EXTERN_API_C( OSStatus )
  603. USBExpertFatalError                (USBDeviceRef             ref,
  604.                                  OSStatus                 status,
  605.                                  void *                    pointer,
  606.                                  UInt32                 value);
  607.  
  608. EXTERN_API_C( OSStatus )
  609. USBExpertNotify                    (void *                    note);
  610.  
  611. EXTERN_API_C( OSStatus )
  612. USBExpertStatusLevel            (UInt32                 level,
  613.                                  USBDeviceRef             ref,
  614.                                  StringPtr                 status,
  615.                                  UInt32                 value);
  616.  
  617. EXTERN_API_C( OSStatus )
  618. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  619.                                  UInt32                 reserved1,
  620.                                  UInt32                 reserved2,
  621.                                  UInt32                 powerStatus,
  622.                                  UInt32                 busPowerAvailable,
  623.                                  UInt32                 busPowerNeeded);
  624.  
  625. enum {
  626.     kUSBDevicePower_PowerOK        = 0,
  627.     kUSBDevicePower_BusPowerInsufficient = 1,
  628.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  629.     kUSBDevicePower_SelfPowerInsufficient = 3,
  630.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  631.     kUSBDevicePower_HubPortOk    = 5,
  632.     kUSBDevicePower_HubPortOverCurrent = 6,
  633.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  634.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  635.     kUSBDevicePower_Reserved3    = 9,
  636.     kUSBDevicePower_Reserved4    = 10
  637. };
  638.  
  639.  
  640. /* For hubs only */
  641. EXTERN_API_C( OSStatus )
  642. USBHubAddDevice                    (USBPB *                pb);
  643.  
  644. EXTERN_API_C( OSStatus )
  645. USBHubConfigurePipeZero            (USBPB *                pb);
  646.  
  647. EXTERN_API_C( OSStatus )
  648. USBHubSetAddress                (USBPB *                pb);
  649.  
  650. EXTERN_API_C( OSStatus )
  651. USBHubDeviceRemoved                (USBPB *                pb);
  652.  
  653.  
  654. EXTERN_API_C( UInt8 )
  655. USBMakeBMRequestType            (UInt8                     direction,
  656.                                  UInt8                     reqtype,
  657.                                  UInt8                     recipient);
  658.  
  659. EXTERN_API_C( OSStatus )
  660. USBControlRequest                (USBPB *                pb);
  661.  
  662.  
  663. typedef UInt32                             USBLocationID;
  664. enum {
  665.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  666. };
  667.  
  668.  
  669. enum {
  670.     kNoDeviceRef                = -1
  671. };
  672.  
  673. /* Status Level constants*/
  674. /*
  675. Level 1: Fatal errors
  676. Level 2: General errors that may or may not effect operation
  677. Level 3: General driver messages.  The "AddStatus" call that drivers use comes through as a level 3.  This is also the default level at boot time.
  678. Level 4: Important status messages from the Expert and USL.
  679. Level 5: General status messages from the Expert and USL.
  680. */
  681. enum {
  682.     kUSBStatusLevelFatal        = 1,
  683.     kUSBStatusLevelError        = 2,
  684.     kUSBStatusLevelClient        = 3,
  685.     kUSBStatusLevelGeneral        = 4,
  686.     kUSBStatusLevelVerbose        = 5
  687. };
  688.  
  689. /* Expert Notification Types*/
  690. typedef UInt8                             USBNotificationType;
  691. typedef UInt8                             USBDriverMessage;
  692. enum {
  693.     kNotifyAddDevice            = 0x00,
  694.     kNotifyRemoveDevice            = 0x01,
  695.     kNotifyAddInterface            = 0x02,
  696.     kNotifyRemoveInterface        = 0x03,
  697.     kNotifyGetDeviceDescriptor    = 0x04,
  698.     kNotifyGetInterfaceDescriptor = 0x05,
  699.     kNotifyGetNextDeviceByClass    = 0x06,
  700.     kNotifyGetDriverConnectionID = 0x07,
  701.     kNotifyInstallDeviceNotification = 0x08,
  702.     kNotifyRemoveDeviceNotification = 0x09,
  703.     kNotifyDeviceRefToBusRef    = 0x0A,
  704.     kNotifyDriverNotify            = 0x0C,
  705.     kNotifyParentNotify            = 0x0D,
  706.     kNotifyAnyEvent                = 0xFF,
  707.     kNotifyPowerState            = 0x17,
  708.     kNotifyStatus                = 0x18,
  709.     kNotifyFatalError            = 0x19
  710. };
  711.  
  712. /*
  713.    USB Manager wildcard constants for USBGetNextDeviceByClass
  714.    and USBInstallDeviceNotification.
  715. */
  716. typedef UInt16                             USBManagerWildcard;
  717. enum {
  718.     kUSBAnyClass                = 0xFFFF,
  719.     kUSBAnySubClass                = 0xFFFF,
  720.     kUSBAnyProtocol                = 0xFFFF,
  721.     kUSBAnyVendor                = 0xFFFF,
  722.     kUSBAnyProduct                = 0xFFFF
  723. };
  724.  
  725.  
  726.  
  727.  
  728. struct ExpertNotificationData {
  729.     USBNotificationType             notification;
  730.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  731.     USBDeviceRef *                    deviceRef;
  732.     UInt32                             busPowerAvailable;
  733.     void *                            data;
  734.     UInt32                             info1;
  735.     UInt32                             info2;
  736. };
  737. typedef struct ExpertNotificationData    ExpertNotificationData;
  738. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  739. /* Definition of function pointer passed in ExpertEntryProc*/
  740. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  741. /* Definition of expert's callback installation function*/
  742. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  743. /* Device Notification Callback Routine*/
  744. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  745. /* Device Notification Parameter Block*/
  746.  
  747. struct USBDeviceNotificationParameterBlock {
  748.     UInt16                             pbLength;
  749.     UInt16                             pbVersion;
  750.     USBNotificationType             usbDeviceNotification;
  751.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  752.     USBDeviceRef                     usbDeviceRef;
  753.     UInt16                             usbClass;
  754.     UInt16                             usbSubClass;
  755.     UInt16                             usbProtocol;
  756.     UInt16                             usbVendor;
  757.     UInt16                             usbProduct;
  758.     OSStatus                         result;
  759.     UInt32                             token;
  760.     USBDeviceNotificationCallbackProcPtr  callback;
  761.     UInt32                             refcon;
  762. };
  763. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  764. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  765. /* Definition of USBDriverNotificationCallback Routine*/
  766. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  767. /* Public Functions*/
  768. EXTERN_API_C( OSStatus )
  769. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  770.                                  CFragConnectionID *    connID,
  771.                                  UInt16                 theClass,
  772.                                  UInt16                 theSubClass,
  773.                                  UInt16                 theProtocol);
  774.  
  775. EXTERN_API_C( OSStatus )
  776. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  777.                                  USBDeviceDescriptor *    deviceDescriptor,
  778.                                  UInt32                 size);
  779.  
  780. EXTERN_API_C( OSStatus )
  781. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  782.                                  USBInterfaceDescriptor * interfaceDescriptor,
  783.                                  UInt32                 size);
  784.  
  785. EXTERN_API_C( OSStatus )
  786. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  787.                                  CFragConnectionID *    connID);
  788.  
  789. EXTERN_API_C( void )
  790. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  791.  
  792. EXTERN_API_C( OSStatus )
  793. USBRemoveDeviceNotification        (UInt32                 token);
  794.  
  795. EXTERN_API_C( OSStatus )
  796. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  797.                                  USBBusRef *            busRef);
  798.  
  799. EXTERN_API_C( OSStatus )
  800. USBDriverNotify                    (USBReference             reference,
  801.                                  USBDriverMessage         mesg,
  802.                                  UInt32                 refcon,
  803.                                  USBDriverNotificationCallbackPtr  callback);
  804.  
  805. EXTERN_API_C( OSStatus )
  806. USBExpertNotifyParent            (USBReference             reference,
  807.                                  void *                    pointer);
  808.  
  809. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  810. typedef CALLBACK_API_C( void , HIDNotificationProcPtr )(UInt32 refcon, UInt32 reportSize, void *theReport, USBReference theInterfaceRef);
  811. /* HID Install Interrupt prototype*/
  812. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  813. /* HID Poll Device prototype*/
  814. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  815. /* HID Control Device prototype*/
  816. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  817. /* HID Get Device Info prototype*/
  818. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  819. /* HID Enter Polled Mode prototype*/
  820. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  821. /* HID Exit Polled Mode prototype*/
  822. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  823. /* HID Install Notification prototype*/
  824. typedef CALLBACK_API_C( OSStatus , USBHIDInstallNotificationProcPtr )(HIDNotificationProcPtr pNotificationProc, UInt32 refcon);
  825. enum {
  826.     kHIDStandardDispatchVersion    = 0,
  827.     kHIDReservedDispatchVersion    = 1,
  828.     kHIDNotificationDispatchVersion = 2,
  829.     kHIDCurrentDispatchVersion    = 2
  830. };
  831.  
  832.  
  833.  
  834. struct USBHIDRev2DispatchTable {
  835.     UInt32                             hidDispatchVersion;
  836.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  837.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  838.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  839.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  840.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  841.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  842.     USBHIDInstallNotificationProcPtr  pUSBHIDInstallNotification;
  843. };
  844. typedef struct USBHIDRev2DispatchTable    USBHIDRev2DispatchTable;
  845. typedef USBHIDRev2DispatchTable *        USBHIDRev2DispatchTablePtr;
  846.  
  847. struct USBHIDModuleDispatchTable {
  848.     UInt32                             hidDispatchVersion;
  849.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  850.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  851.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  852.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  853.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  854.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  855. };
  856. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  857. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  858. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  859. EXTERN_API_C( OSStatus )
  860. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  861.                                  UInt32                 refcon);
  862.  
  863. EXTERN_API_C( OSStatus )
  864. USBHIDPollDevice                (void);
  865.  
  866. EXTERN_API_C( OSStatus )
  867. USBHIDControlDevice                (UInt32                 theControlSelector,
  868.                                  void *                    theControlData);
  869.  
  870. EXTERN_API_C( OSStatus )
  871. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  872.                                  void *                    theInfo);
  873.  
  874. EXTERN_API_C( OSStatus )
  875. USBHIDEnterPolledMode            (void);
  876.  
  877. EXTERN_API_C( OSStatus )
  878. USBHIDExitPolledMode            (void);
  879.  
  880. EXTERN_API_C( OSStatus )
  881. USBHIDInstallNotification        (HIDNotificationProcPtr  HIDNotificationFunction,
  882.                                  UInt32                 refcon);
  883.  
  884. EXTERN_API_C( void )
  885. HIDNotification                    (UInt32                 devicetype,
  886.                                  UInt8                     NewHIDData[],
  887.                                  UInt8                     OldHIDData[]);
  888.  
  889. enum {
  890.     kHIDRqGetReport                = 1,
  891.     kHIDRqGetIdle                = 2,
  892.     kHIDRqGetProtocol            = 3,
  893.     kHIDRqSetReport                = 9,
  894.     kHIDRqSetIdle                = 10,
  895.     kHIDRqSetProtocol            = 11
  896. };
  897.  
  898. enum {
  899.     kHIDRtInputReport            = 1,
  900.     kHIDRtOutputReport            = 2,
  901.     kHIDRtFeatureReport            = 3
  902. };
  903.  
  904. enum {
  905.     kHIDBootProtocolValue        = 0,
  906.     kHIDReportProtocolValue        = 1
  907. };
  908.  
  909. enum {
  910.     kHIDKeyboardInterfaceProtocol = 1,
  911.     kHIDMouseInterfaceProtocol    = 2
  912. };
  913.  
  914. enum {
  915.     kHIDSetLEDStateByBits        = 1,
  916.     kHIDSetLEDStateByBitMask    = 1,
  917.     kHIDSetLEDStateByIDNumber    = 2,
  918.     kHIDRemoveInterruptHandler    = 3,
  919.     kHIDEnableDemoMode            = 4,
  920.     kHIDDisableDemoMode            = 5,
  921.     kHIDRemoveNotification        = 0x1000
  922. };
  923.  
  924. enum {
  925.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  926.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  927.     kHIDGetLEDStateByIDNumber    = 2,
  928.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  929.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  930.     kHIDGetInterruptHandler        = 5,
  931.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  932.     kHIDGetInterruptRefcon        = 7,
  933.     kHIDGetVendorID                = 8,
  934.     kHIDGetProductID            = 9
  935. };
  936.  
  937.  
  938. enum {
  939.     kNumLockLED                    = 0,
  940.     kCapsLockLED                = 1,
  941.     kScrollLockLED                = 2,
  942.     kComposeLED                    = 3,
  943.     kKanaLED                    = 4
  944. };
  945.  
  946. enum {
  947.     kNumLockLEDMask                = 1 << kNumLockLED,
  948.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  949.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  950.     kComposeLEDMask                = 1 << kComposeLED,
  951.     kKanaLEDMask                = 1 << kKanaLED
  952. };
  953.  
  954. enum {
  955.     kUSBCapsLockKey                = 0x39,
  956.     kUSBNumLockKey                = 0x53,
  957.     kUSBScrollLockKey            = 0x47
  958. };
  959.  
  960.  
  961. struct USBMouseData {
  962.     UInt16                             buttons;
  963.     SInt16                             XDelta;
  964.     SInt16                             YDelta;
  965. };
  966. typedef struct USBMouseData                USBMouseData;
  967. typedef USBMouseData *                    USBMouseDataPtr;
  968.  
  969. struct USBKeyboardData {
  970.     UInt16                             keycount;
  971.     UInt16                             usbkeycode[32];
  972. };
  973. typedef struct USBKeyboardData            USBKeyboardData;
  974. typedef USBKeyboardData *                USBKeyboardDataPtr;
  975.  
  976. union USBHIDData {
  977.     USBKeyboardData                 kbd;
  978.     USBMouseData                     mouse;
  979. };
  980. typedef union USBHIDData                USBHIDData;
  981. typedef USBHIDData *                    USBHIDDataPtr;
  982. EXTERN_API_C( void )
  983. StartCompoundClassDriver        (USBDeviceRef             device,
  984.                                  UInt16                 classID,
  985.                                  UInt16                 subClass);
  986.  
  987. enum {
  988.     kUSBCompositeClass            = 0,
  989.     kUSBAudioClass                = 1,
  990.     kUSBCommClass                = 2,
  991.     kUSBHIDClass                = 3,
  992.     kUSBDisplayClass            = 4,
  993.     kUSBPrintingClass            = 7,
  994.     kUSBMassStorageClass        = 8,
  995.     kUSBHubClass                = 9,
  996.     kUSBDataClass                = 10,
  997.     kUSBVendorSpecificClass        = 0xFF
  998. };
  999.  
  1000. enum {
  1001.     kUSBCompositeSubClass        = 0,
  1002.     kUSBHubSubClass                = 1,
  1003.     kUSBPrinterSubclass            = 1
  1004. };
  1005.  
  1006. enum {
  1007.     kUSBHIDInterfaceClass        = 0x03
  1008. };
  1009.  
  1010. enum {
  1011.     kUSBNoInterfaceSubClass        = 0x00,
  1012.     kUSBBootInterfaceSubClass    = 0x01
  1013. };
  1014.  
  1015. enum {
  1016.     kUSBNoInterfaceProtocol        = 0x00,
  1017.     kUSBKeyboardInterfaceProtocol = 0x01,
  1018.     kUSBMouseInterfaceProtocol    = 0x02
  1019. };
  1020.  
  1021. enum {
  1022.     kUSBPrinterUnidirectionalProtocol = 0x01,
  1023.     kUSBPrinterBidirectionalProtocol = 0x02
  1024. };
  1025.  
  1026.  
  1027. enum {
  1028.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  1029. };
  1030.  
  1031. /* SOMETHING NEEDS TO BE DONE WITH THIS - */
  1032. enum {
  1033.     kUSBTypeIsHub                = FOUR_CHAR_CODE('hubd'),        /* Hub*/
  1034.     kUSBTypeIsHID                = FOUR_CHAR_CODE('HIDd'),        /* Human Interface Device*/
  1035.     kUSBTypeIsDisplay            = FOUR_CHAR_CODE('disp'),        /* Display */
  1036.     kUSBTypeIsModem                = FOUR_CHAR_CODE('modm')        /* Modem*/
  1037. };
  1038.  
  1039. enum {
  1040.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  1041.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  1042.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  1043. };
  1044.  
  1045. enum {
  1046.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  1047. };
  1048.  
  1049. enum {
  1050.     kInitialUSBDriverDescriptor    = 0
  1051. };
  1052.  
  1053.  
  1054.  
  1055. typedef UInt32                             USBDriverDescVersion;
  1056. /*  Driver Loading Options*/
  1057. typedef UInt32                             USBDriverLoadingOptions;
  1058. enum {
  1059.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1060.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1061.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1062.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1063. };
  1064.  
  1065. enum {
  1066.     kClassDriverPluginVersion    = 0x00001100
  1067. };
  1068.  
  1069.  
  1070.  
  1071.  
  1072. struct USBDeviceInfo {
  1073.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1074.     UInt16                             usbProductID;                /* USB Product ID.*/
  1075.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1076.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1077. };
  1078. typedef struct USBDeviceInfo            USBDeviceInfo;
  1079. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1080.  
  1081. struct USBInterfaceInfo {
  1082.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1083.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1084.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1085.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1086.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1087. };
  1088. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1089. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1090.  
  1091. struct USBDriverType {
  1092.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1093.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1094.     UInt8                             usbDriverSubClass;            /* Module type*/
  1095.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1096. };
  1097. typedef struct USBDriverType            USBDriverType;
  1098. typedef USBDriverType *                    USBDriverTypePtr;
  1099.  
  1100. struct USBDriverDescription {
  1101.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1102.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1103.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1104.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1105.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1106.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1107. };
  1108. typedef struct USBDriverDescription        USBDriverDescription;
  1109. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1110. /*
  1111.    Dispatch Table
  1112.    Definition of class driver's HW Validation proc.
  1113. */
  1114. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1115. /*
  1116.    Definition of class driver's device initialization proc.
  1117.    Called if the driver is being loaded for a device
  1118. */
  1119. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1120. /* Definition of class driver's interface initialization proc.*/
  1121. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1122. /* Definition of class driver's finalization proc.*/
  1123. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1124.  
  1125. typedef UInt32                             USBDriverNotification;
  1126. enum {
  1127.     kNotifySystemSleepRequest    = 0x00000001,
  1128.     kNotifySystemSleepDemand    = 0x00000002,
  1129.     kNotifyHubEnumQuery            = 0x00000006,
  1130.     kNotifyChildMessage            = 0x00000007,
  1131.     kNotifyExpertTerminating    = 0x00000008,
  1132.     kNotifyDriverBeingRemoved    = 0x0000000B
  1133. };
  1134.  
  1135. /*
  1136.    Definition of driver's notificatipn proc.      
  1137.    Added refcon for 1.1 version of dispatch table
  1138. */
  1139. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1140.  
  1141. struct USBClassDriverPluginDispatchTable {
  1142.     UInt32                             pluginVersion;
  1143.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1144.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1145.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1146.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1147.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1148. };
  1149. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1150. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1151. /* Hub defines*/
  1152.  
  1153.  
  1154. enum {
  1155.     kUSBHubDescriptorType        = 0x29
  1156. };
  1157.  
  1158. enum {
  1159.                                                                 /* Hub features */
  1160.     kUSBHubLocalPowerChangeFeature = 0,
  1161.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1162.     kUSBHubPortConnectionFeature = 0,
  1163.     kUSBHubPortEnablenFeature    = 1,
  1164.     kUSBHubPortSuspecdFeature    = 2,
  1165.     kUSBHubPortOverCurrentFeature = 3,
  1166.     kUSBHubPortResetFeature        = 4,
  1167.     kUSBHubPortPowerFeature        = 8,
  1168.     kUSBHubPortLowSpeedFeature    = 9,
  1169.     kUSBHubPortConnectionChangeFeature = 16,
  1170.     kUSBHubPortEnableChangeFeature = 17,
  1171.     kUSBHubPortSuspendChangeFeature = 18,
  1172.     kUSBHubPortOverCurrentChangeFeature = 19,
  1173.     kUSBHubPortResetChangeFeature = 20
  1174. };
  1175.  
  1176.  
  1177. enum {
  1178.     kHubPortConnection            = 1,
  1179.     kHubPortEnabled                = 2,
  1180.     kHubPortSuspend                = 4,
  1181.     kHubPortOverCurrent            = 8,
  1182.     kHubPortBeingReset            = 16,
  1183.     kHubPortPower                = 0x0100,
  1184.     kHubPortSpeed                = 0x0200
  1185. };
  1186.  
  1187. enum {
  1188.     kHubLocalPowerStatus        = 1,
  1189.     kHubOverCurrentIndicator    = 2,
  1190.     kHubLocalPowerStatusChange    = 1,
  1191.     kHubOverCurrentIndicatorChange = 2
  1192. };
  1193.  
  1194. enum {
  1195.     off                            = false,
  1196.     on                            = true
  1197. };
  1198.  
  1199.  
  1200.  
  1201. struct hubDescriptor {
  1202.                                                                 /* See usbDoc pg 250?? */
  1203.     UInt8                             dummy;                        /* to align charcteristics */
  1204.  
  1205.     UInt8                             length;
  1206.     UInt8                             hubType;
  1207.     UInt8                             numPorts;
  1208.  
  1209.     UInt16                             characteristics;
  1210.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1211.     UInt8                             hubCurrent;
  1212.  
  1213.                                                                 /* These are received packed, will have to be unpacked */
  1214.     UInt8                             removablePortFlags[8];
  1215.     UInt8                             pwrCtlPortFlags[8];
  1216. };
  1217. typedef struct hubDescriptor            hubDescriptor;
  1218.  
  1219.  
  1220.  
  1221. #if PRAGMA_STRUCT_ALIGN
  1222.     #pragma options align=reset
  1223. #elif PRAGMA_STRUCT_PACKPUSH
  1224.     #pragma pack(pop)
  1225. #elif PRAGMA_STRUCT_PACK
  1226.     #pragma pack()
  1227. #endif
  1228.  
  1229. #ifdef PRAGMA_IMPORT_OFF
  1230. #pragma import off
  1231. #elif PRAGMA_IMPORT
  1232. #pragma import reset
  1233. #endif
  1234.  
  1235. #ifdef __cplusplus
  1236. }
  1237. #endif
  1238.  
  1239. #endif /* __USB__ */
  1240.  
  1241.